package com.my.java_web.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONObject;
import com.my.java_web.domain.User;
import com.my.java_web.service.UserService;
import com.my.java_web.service.impl.UserServiceImpl;

@WebServlet("/users/del")
public class UserDeleteServlet extends HttpServlet{
	private UserService userService = new UserServiceImpl();

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
//		super.doPost(req, resp);
		String ids = req.getParameter("ids");//多个id用逗号分隔
		String[] id = ids.split(",");
		for(String i : id) {
			User user = new User();
			user.setId(Integer.parseInt(i));
			userService.del(user);
		}
		//更新缓存
//		InitListener.userCache = null;
		
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("result", "success");
	}

	@Override
	protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		super.doDelete(req, resp);
	}
	

}
